﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Happy.Examples.OrderManagement.Domain.Orders.States
{
    internal abstract class OrderState
    {
        public Order Order { get; set; }

        public void BeforeChangeOrder()
        {
            if (!this.CanChangeOrder())
            {
                throw new InvalidOperationException(string.Format("订单处于“{0}”状态，不能修改订单信息！", this.Status));
            }
        }

        protected virtual bool CanChangeOrder() { return false; }

        public virtual void Save()
        {
            throw new InvalidOperationException(string.Format("订单处于“{0}”状态，不能执行保存操作！", this.Status));
        }

        public virtual void Submit()
        {
            throw new InvalidOperationException(string.Format("订单处于“{0}”状态，不能执提交存操作！", this.Status));
        }

        public virtual void Audit()
        {
            throw new InvalidOperationException(string.Format("订单处于“{0}”状态，不能执行审核操作！", this.Status));
        }

        public abstract OrderStatus Status { get; }
    }
}
